package com.clever.mall.utils;

import com.clever.mall.commons.exception.ServiceException;
import lombok.Data;
import lombok.Getter;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.Properties;

/**
 * @author ChenWang
 * @className WalletServerConfig
 * @date 2020/11/10 10:25
 * @since JDK 1.8
 */
public class WalletServerConfig {
    private volatile static WalletServerConfig instance;
    /**
     * 最小金额
     */
    public static BigDecimal MINMONEY;
    /**
     * 最大金额
     */
    public static BigDecimal MAXMONEY;
    /**
     * 到账时间为?--?多少工作日
     * 至少
     */
    public static int ATLEASTDAY;
    /**
     * 到账时间为?--?多少工作日
     * 至多
     */
    public static int ATTHEMOSTDAY;

    /**
     * 客服微信
     */
    public static String SERVERVECHAT;

    /**
     * 加载配置文件
     */
    static{
        Properties properties = new Properties();
        InputStream resourceAsStream = WalletServerConfig.class.getClassLoader().getResourceAsStream("wallet.properties");
        try {
            properties.load(resourceAsStream);
        } catch (IOException e) {
            throw new ServiceException(StatusCode.SERVER_ERROR);
        }

        MINMONEY = new BigDecimal(properties.getProperty("minMoney"));
        MAXMONEY = new BigDecimal(properties.getProperty("maxMoney"));
        ATLEASTDAY = Integer.parseInt(properties.getProperty("atLeastDay"));
        ATTHEMOSTDAY = Integer.parseInt(properties.getProperty("atTheMostDay"));
        SERVERVECHAT = properties.getProperty("serverVechat");
    }


    private WalletServerConfig(){}

    /**
     * 单例模式  获取当前类的对象
     * @return  当前类对象
     */
    public static WalletServerConfig getInstance() {
        if(instance==null){
            synchronized (WalletServerConfig.class){
                if(instance==null){
                    instance = new WalletServerConfig();
                }
            }
        }
        return instance;
    }
}
